package com.zgscwjm.taobaphelper.ui;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.zgscwjm.taobaphelper.MainActivity;
import com.zgscwjm.taobaphelper.UpdateActivity;
import com.zgscwjm.taobaphelper.data.AccountBean;
import com.zgscwjm.taobaphelper.exutils.MyBaseConfig;
import com.zgscwjm.taobaphelper.exutils.StringUtils;
import com.zgscwjm.taobaphelper.xp.FileManager;

/**
 * Created by fukunaka on 2017/3/14.
 */

public class ar extends Handler {
    final MainActivity mainActivity;

    public ar(MainActivity mainActivity){
        this.mainActivity=mainActivity;
    }

    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
    try {
        if (MainActivity.progressDialog!= null)
        {
            MainActivity.progressDialog.dismiss();
        }
        int intvalue;
        int a;
        String a2;
        switch (msg.what)
        {
            case 100:
             case 101:
                 this.mainActivity.tv_username.setText((String)msg.obj);
                return;
             case 102:
                 intvalue= ((Integer) msg.obj).intValue();
                 a= UpdateActivity.getVersioncode(this.mainActivity, MyBaseConfig.TBpacgename);
                 a2=MainActivity.getVersionName(this.mainActivity,MyBaseConfig.TBpacgename);
                 if (intvalue>a)
                 {
                     this.mainActivity.tv_taobaoversion.setText("监测到新版本");

                 }
                 else {
                     this.mainActivity.tv_taobaoversion.setText("当前版本： "+a2);
                 }
                 return;
             case 104:
                 intvalue= ((Integer) msg.obj).intValue();
                 a= UpdateActivity.getVersioncode(this.mainActivity, MyBaseConfig.Mypackagename);
                 a2=MainActivity.getVersionName(this.mainActivity,MyBaseConfig.Mypackagename);
                 if (intvalue>a)
                 {
                     this.mainActivity.tv_currentVersion.setText("监测到新版本");

                 }
                 else {
                     this.mainActivity.tv_currentVersion.setText("当前版本： "+a2);
                 }
                return;
             case 200:
                 this.mainActivity.tv_errorTip.setText((String)msg.obj);
                return;
             case 201:
                 AccountBean readAccBean = FileManager.readAccBean();
                 if (readAccBean==null || StringUtils.isEmpty(readAccBean.getRealname()))
                 {
                     this.mainActivity.tv_wangwangName.setText("旺旺为空！");
                     return;
                 }
                 String realname=readAccBean.getRealname();
                 MainActivity.s=  realname;
                 this.mainActivity.tv_wangwangName.setText(realname);
                return;
             case 202:
             case 203:
                 this.mainActivity.tv_currentUserPoints.setText((String)msg.obj);
                return;
             case 600:
                 if (((Integer)msg.obj).intValue()==1)
                 {
                     this.mainActivity.tv_errorTip.setText("初始环境测试成功，可以开始任务！");
                 }else if (!MainActivity.E && !this.mainActivity.D)
                 {
                     this.mainActivity.F=0;
                     this.mainActivity.tv_errorTip.setText("开始测试初始环境！");
                     this.mainActivity.f();
                 }
                return;
             case 601:
                 if (!this.mainActivity.D){
                     if (this.mainActivity.F>8)
                     {
                         this.mainActivity.showMessage("手机不匹配","监测到应用与该手机不匹配，不能执行无线流量任务");
                     return;
                     }
                     this.mainActivity.F+=1;
                     this.mainActivity.f();
                 }
                return;
             case 602:
                 String str= (String) msg.obj;
                 this.mainActivity.showMessage("环境配置失败！",str);
                return;
             default:
                 this.mainActivity.tv_errorTip.setText("获取小号失败！！");
                 return;
        }
    }
    catch (Exception e)
    {
        Log.e(this.mainActivity.getLocalClassName(),e.getMessage());
    }
    }
}
